package com.example.Lezedata.ui.fragment.person;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.Lezedata.R;
import com.example.Lezedata.dataManager.GBUserManager;
import com.example.Lezedata.ui.activity.person.DepositVc;
import com.example.Lezedata.ui.activity.person.PersonSetHeadVc;
import com.example.Lezedata.ui.activity.person.WithDrawalVc;
import com.example.Lezedata.ui.activity.record.BidRecordVc;
import com.example.Lezedata.ui.activity.record.PrizesRecord;
import com.example.Lezedata.ui.fragment.BaseFragment;
import com.example.Lezedata.util.GBUtil;

import io.grpc.Context;

public class PersonHeaderView extends BaseFragment {

    private ImageView headPortrait;
    private TextView name;
    private TextView money;

    public static PersonHeaderView newInstance() {
        return new PersonHeaderView();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.person_header_view, container, false);
    }

    @Override
    public void initView() {
        super.initView();

        findViewById(R.id.Deposit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseVc().jumpActivity(DepositVc.class);
            }
        });

        findViewById(R.id.Withdraw).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseVc().jumpActivity(WithDrawalVc.class);
            }
        });

        findViewById(R.id.MyPrizes).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseVc().jumpActivity(PrizesRecord.class);
            }
        });

        findViewById(R.id.BidRecords).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseVc().jumpActivity(BidRecordVc.class);
            }
        });

        headPortrait = findViewById(R.id.person_head);
        headPortrait.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(baseVc(), PersonSetHeadVc.class);
                baseVc().jumpActivityIntent(intent,1);
            }
        });

        name = findViewById(R.id.person_name);
        money = findViewById(R.id.money);
        setData();
    }

    void setData(){
        GBUtil.setHeadImage(headPortrait,GBUserManager.userInfo().getProfileUrl());
        name.setText(GBUserManager.userInfo().getPhone());
        money.setText(String.valueOf(GBUserManager.instance().balance));
    }
}
